<?php

namespace App\Model;

use App\Comment\Comment;
use Illuminate\Database\Eloquent\Model;

class BizTable extends Model
{
    public $timestamps = false;
    protected $table = 'biz_table';


    /**
     * 根据商户获取餐台列表
     * @return mixed
     */
    public function getTableListByBiz()
    {
        return BizTable::where(['biz_id' => Comment::getBizId()]) -> get() -> toArray();
    }

    /**
     * 添加餐台信息
     * @param $data
     * @return mixed
     */
    public function addTable($data)
    {
        $data['index'] = $this -> where(['biz_id' => Comment::getBizId()]) -> max('index') + 1;
        return $this -> insertGetId($data);
    }

    /**
     * 删除餐台信息
     * @param $id
     * @return mixed
     */
    public function delTable($id)
    {
        return $this -> where(['id' => $id]) -> delete();
    }

    /**
     * 获取餐台的详情
     * @param $id
     * @return mixed
     */
    public function getTableInfoById($id)
    {
        return $this -> where(['id' => $id]) -> first() -> toArray();
    }

    /**
     * 修改餐台信息
     * @param $id
     * @param $data
     * @return mixed
     */
    public function updateTable($id, $data)
    {
        return $this -> where(['id' => $id]) -> update($data);
    }
}
